<template>
	<view class="reply-container">
		<view style="padding: 20rpx;">
			<view class="toast-top">
				<view class="flex">
					<text style="color: red;">*</text>
					<view class="desc">转派人员</view>
				</view>
				
			</view>
			
			<view class="c-input">
				<!-- <text @click="handleTap('picker')" :class="{color: label === '请选择转派人员'}">{{label}}</text>
				<lb-picker ref="picker" mode="selector" :list="workerList" :dataset="{ name: 'label' }"
				 @change="handleChange" @confirm="handleConfirm" @cancel="handleCancel">
				</lb-picker> -->
				<song-data-picker :bigText="true" :noPadding="true" placeholder="请选择处理人员" :showArrow="false" :border="false" ref="songPicker" :localdata="workerList" popup-title="请选择" :openSearch="true" @change="onChange" @nodeclick="onnodeclick"></song-data-picker>
			</view>
			<!-- <view class="toast-top">
				<view class="flex">
					<text style="color: #fff;">*</text>
					<view class="desc">完成时限</view>
				</view>
			</view>
			<view class="c-input">
				<input type="number" v-model="params['时限']" placeholder="请输入完成时限">
			</view>
			<view class="toast-top">
				<view class="flex">
					<text style="color: #fff;">*</text>
					<view class="desc">时限单位</view>
				</view>
			</view>
			<view @click="handleTap('picker1')" class="c-input">
				<text :class="{color: label1 === '请选择时限单位'}">{{label1}}</text>
				<lb-picker ref="picker1" mode="selector" :list="delayTypeList" :dataset="{ name: 'label1' }"
				 @change="handleChange" @confirm="handleConfirm1" @cancel="handleCancel">
				</lb-picker>
			</view> -->
			<!-- <view v-if="!params['转派人员id']" :class="label1 == '请选择任务执行人' ? 'color':''" class="tap"
				@click="toChoose(query,3)">{{label1}}</view>
			
			<view @click="toChoose1(query,3)" v-for="(item,index) in params['执行人']"
				style="margin: 2px;display: inline-block;" :key="index">
				<text>{{item}};</text>
			</view>
			<input class="c-input" type="text" disabled placeholder="请选择转派人员"> -->
			<view class="toast-top">
				<view class="flex">
					<text style="color: red;">*</text>
					<view class="desc">转派原因</view>
				</view>
			</view>
			<!-- <view class="title"><text style="color: red;">*</text>评价描述</view> -->
			<textarea style="height: 320rpx;" v-model="params['操作原因']" class="content" placeholder="请输入转派原因..." name="" id="" cols="30" rows="10"></textarea>
		</view>
		<button class="btn" @click="submit">提交</button>
	</view>
</template>

<script>
	import LbPicker from '@/components/lb-picker'
	export default {
		components: {
			LbPicker
		},
		data() {
			return {
				delayTypeList: this.$type.delayTypeList,
				label: '请选择转派人员',
				label1: '请选择时限单位',
				workerList: [],
				params: {
					id: null,
					接单人id: null,
					操作原因: '',
					时限: null,
					时限单位: null
				},
				params1: {
					orgId: null,
					projectIds: null,
					pagination: {
						current: 1,
						pageSize: 100
					},
					sorter: {
						field: "id",
						order: 0
					}
				}
			}
		},
		onLoad(options) {
			this.params.id = +options.id
			this.params1.projectIds = [+options.projId]
			this.getOperatorList()
		},
		methods: {
			onChange(e) {
				this.params.接单人id = e.detail.value[0].id
			},
			submit() {
				if (!this.params.接单人id) {
					uni.showToast({
						title: '请选择转派人员',
						icon: 'none'
					})
				} else if (this.params.操作原因.trim() == '') {
					uni.showToast({
						title: '请填写转派原因',
						icon: 'none'
					})
				} else {
					// this.params.时限 = this.params.时限 && parseInt(this.params.时限)
					// let params = JSON.parse(JSON.stringify(this.params))
					// if(params.时限单位 === '小时') {
					// 	params.时限 = params.时限 * 60
					// }else if(params.时限单位 === '天') {
					// 	params.时限 = params.时限 * 1440
					// }
					this.transferTicket(this.params)
				}
			},
			getOperatorList() {
				// this.params1.单位id = uni.getStorageSync('currentUnitId')
				this.$http2.post('/sys/user/list', this.params1).then(res => {
					// console.log(res, '处理人员')
					if (res.code === 10000) {
						if (res.data.list !== null) {
							res.data.list.forEach(item => {
								item.value = item.id
								item.text = item.name
							})
						}
						this.workerList = res.data.list.filter(item => item.id !== uni.getStorageSync('userInfo').id)
					}
				})
			},
			getWorkerList() {
				this.$http2.post('worksys/worker/list', this.params1).then(res => {
					if(res.code === 10000) {
						// console.log(res)
						res.data.list = res.data.list || []
						res.data.list.forEach(item => {
							item.value = item.id
							item.text = item.人员名称
						})
						this.workerList = res.data.list.filter(item => item.id !== uni.getStorageSync('userInfo').id)
					}
				})
			},
			transferTicket(params) {
				uni.showLoading({
					mask: true
				})
				this.$http2.post('ticketSystem/ticket/assign', params).then(res => {
					// console.log(res)
					if (res.code === 10000) {
						uni.redirectTo({
							url: '/ticketSystem/acceptSuccess/acceptSuccess?path=../index/index' + '&title=返回工单首页'
						})
						
					}
				})
			},
			handleTap(name) {
				this.$refs[name].show()
			},
			handleChange(e) {
				console.log('change::', e)
			},
			handleConfirm1(e) {
				if(e) {
					const name = e.dataset.name
					const label = e.item
					console.log(e)
					this.params.时限单位 = e.value
					// this.params.unit = e.item.id
					// this.params4.education = e.item.id
					if(name && label){
						this[name] = label
					}
				}
			},
			handleConfirm(e) {
				// 如果存在多个picker，可以在picker上设置dataset属性，confirm中获取，就能区分是哪个picker了
				console.log('confirm::', e)
				if (e) {
					const name = e.dataset.name
					this.params.接单人id = e.item.id
					// this.params.负责工单类型 = e.item.id
					// this.params2.所属项目id = e.item.id
					const label = e.item.label
					if (name && label) {
						this[name] = label
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.color {
		color: #808080;
	}
	.reply-container {
		height: 100vh;
		// padding-bottom: 100rpx;
		// padding: 20rpx;
		.flex {
			display: flex;
			align-items: center;
		}

		.title {
			margin-bottom: 30rpx;
		}
		.c-input {
			padding-left: 20rpx;
			border: 2rpx solid #ccc;
			height: 70rpx;
			display: flex;
			align-items: center;
		}
		.content {
			width: 710rpx;
			padding: 20rpx;
			border: 2rpx solid #ccc;
		}

		.btn {
			width: 568rpx;
			height: 80rpx;
			line-height: 80rpx;
			margin-top: 120rpx;
			background-color: #1152FC;
			color: #fff;
		}

		.toast-top {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 20rpx;
			margin-top: 20rpx;
			.desc {
				margin-right: 20rpx;
				font-size: 36rpx;
			}

			.desc-text {
				color: #BCBCBC;
				font-size: 30rpx;
				margin-left: 18rpx;
			}
		}
	}
</style>
